﻿using System;
using System.Diagnostics.CodeAnalysis;

namespace EnterpriseLibraryExtensions.Events
{
    /// <summary>
    /// The EnlistedEventHandler class is used by the aggregation scope when events are raised. The class
    /// keeps track of who raised it (sender), the arguments (args) and the actual event handler that is to handle the event if it is
    /// to be raised on scope complete.
    /// </summary>
    [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "The name is intentional")]
    internal class EnlistedEventHandler : IEnlistedEventHandler
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EnlistedEventHandler"/> class.
        /// </summary>
        /// <param name="sender">The sender. This value can be null.</param>
        /// <param name="args">The args. This value cannot be null.</param>
        /// <param name="eventHandler">The event handler. The implementation to handle the event. This value cannot be null.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if args or eventHandler is null.</exception>
        public EnlistedEventHandler(object sender, object args, IHandlesEvent eventHandler)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (eventHandler == null)
            {
                throw new ArgumentNullException("eventHandler");
            }

            this.Sender = sender;
            this.Args = args;
            this.EventHandler = eventHandler;
        }

        /// <summary>
        /// Gets the sender. The sender is the object instance that raised the event.
        /// This value can be null.
        /// </summary>
        /// <value>The sender.</value>
        public object Sender { get; private set; }

        /// <summary>
        /// Gets the arguments. The arguments are passed to the event handler when the event aggregation scope
        /// determines that the event handler should be invoked.
        /// </summary>
        /// <value>The args which are passed to the event handler on invokation..</value>
        public object Args { get; private set; }

        /// <summary>
        /// Gets the event handler for the event. The event handler is invoked when the event aggregation scope determines it should be called.
        /// </summary>
        /// <value>The event handler.</value>
        public IHandlesEvent EventHandler { get; private set; }
    }
}
